#include <omp.h>
#include <stdio.h>

float dotprod(float B[], float C[], int N){
    int i;
    float sum = 0.0;
    #pragma omp target teams map(to: B[0:N], C[0:N]) defaultmap(tofrom:scalar) reduction(+:sum)
    #pragma omp distribute parallel for reduction(+:sum)
    for (i = 0; i < N; i++) {
        sum += B[i] * C[i];
    }
    return sum;
}

int main() {
    float B[] = {1.0, 2.0, 3.0, 4.0};
    float C[] = {2.0, 2.0, 2.0, 2.0};
    printf("Result: %f\n", dotprod(B, C, 4));//输出应为20.0
    return 0;
}